package com.shawn.spring.boot.jdbc.util;

import java.util.List;

/**
 * @author shawn
 * @since 2020/8/29
 */
public class SqlUtil {

  public static String join(CharSequence split, List<String> list) {
    boolean isFirst = true;
    StringBuilder builder = new StringBuilder();
    for (String str : list) {
      if (isFirst) {
        isFirst = false;
      } else {
        builder.append(split);
      }
      builder.append(str);
    }
    return builder.toString();
  }

  public static String repeatAndJoin(CharSequence repeatStr, CharSequence split, int length) {
    if (length <= 0) {
      return "";
    }
    StringBuilder builder = new StringBuilder();
    boolean isFirst = true;
    while (length-- > 0) {
      if (isFirst) {
        isFirst = false;
      } else {
        builder.append(split);
      }
      builder.append(repeatStr);
    }
    return builder.toString();
  }
}
